import re

def generate_cot(text, label=None):
    """
    根据短信内容和标签生成思维链提示。
    label: 可选，若已知标签，可生成更贴切的提示。
    """
    spam_keywords = [
        'win', 'prize', 'free', 'congratulations', 'claim', 'urgent', 'gift', 'cash', 'award',
        'click', 'buy', 'winner', 'selected', 'offer', 'now', 'call', 'sms', 'http', 'www', 'bit.ly', 'unsubscribe'
    ]
    text_lower = text.lower()
    matched = [kw for kw in spam_keywords if kw in text_lower]
    
    if label == 'spam' or (matched and label is None):
        reason = f"这条短信包含如下可疑词汇：{', '.join(matched)}，通常是垃圾邮件的特征。"
    elif label == 'ham' or (not matched and label is None):
        reason = "这条短信内容是日常交流，没有明显的垃圾邮件特征。"
    else:
        reason = "这条短信内容不确定，需进一步分析。"
    return reason

if __name__ == "__main__":
    # 测试
    print(generate_cot("Congratulations! You have won a $1000 Walmart gift card. Go to http://bit.ly/123456 to claim now.", label='spam'))
    print(generate_cot("Are we still meeting for lunch today?", label='ham')) 